﻿using D.Medicalcare.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace D.Medicalcare.Read.API.Controllers
{
    /// <summary>
    /// 地区控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LocationController : ControllerBase
    {
        private readonly MyDbContext _context;
        /// <summary>
        /// 构造函数注入数据库上下文对象
        /// </summary>
        /// <param name="_context">参数</param>
        public LocationController(MyDbContext _context)
        {
            this._context = _context;
        }
        /// <summary>
        /// 获取省份列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("provinces")]
        public IActionResult GetProvinces()
        {
            var provinces = _context.Province.ToList();
            return Ok(provinces);
        }
        /// <summary>
        /// 根据省份ID获取城市列表
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>

        [HttpGet("cities/{provinceId}")]
        public IActionResult GetCity(int provinceId)
        {
            var cities = _context.City.Where(c => c.ProvinceId == provinceId).ToList();
            return Ok(cities);
        }
        /// <summary>
        /// 根据城市ID获取区县列表
        /// </summary>
        /// <param name="cityId"></param>
        /// <returns></returns>

        [HttpGet("districts/{cityId}")]
        public IActionResult GetCounty(int cityId)
        {
            var districts = _context.County.Where(d => d.CityId == cityId).ToList();
            return Ok(districts);
        }
    }
}
